// sub_xunjian/xunjian_list/xunjian_list.js
const dayjs = require("dayjs");
Page({

  /**
   * 页面的初始数据
   */
  data: {
    list: [],
    pickerList1: [{
      id: '0',
      name: '全部'
    },
    {
      id: '1',
      name: '工业园区'
    },
    {
      id: '2',
      name: '姑苏区'
    },
    {
      id: '3',
      name: '太仓市'
    },
    {
      id: '4',
      name: '吴中区'
    },
    {
      id: '5',
      name: '吴江区'
    },
    {
      id: '6',
      name: '高新区'
    },
    {
      id: '7',
      name: '相城区'
    },
    {
      id: '8',
      name: '昆山市'
    },
    {
      id: '9',
      name: '张家港市'
    },

    {
      id: '10',
      name: '常熟市'
    },


    ],
    selectList1: '全部',
    selectList2: dayjs(new Date()).format('YYYY-MM-DD'),
    pageNum: 1,
    pageSize: 20,

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad (options) {
    this.getList()
  },

  goDetail (e) {
    this.setData({
      needFresh: false
    })
    wx.navigateTo({
      url: `/sub_xunjian/inspection/inspection?id=${e.currentTarget.dataset.id}&type=2`
    })
  },

  editInfo (e) {
    this.setData({
      needFresh: false
    })
    wx.navigateTo({
      url: `/sub_xunjian/inspection/inspection?id=${e.currentTarget.dataset.id}&type=1`
    })
  },

  getList () {
    let params = {
      "pageNum": this.data.pageNum,
      "pageSize": this.data.pageSize,
      "region": this.data.selectList1,
      "time": this.data.selectList2,
      "user_id": wx.getStorageSync('userInfo').userId
    }
    console.log(params);
    getApp()
      .globalData.request("/bcInspection/getDetailPage", params, "POST").then(res => {
        console.log(res);
        this.setData({
          list: this.data.list.concat(res.data.list)
        })
      })
  },
  onChange1 (e) {
    this.setData({
      selectList1: this.data.pickerList1[e.detail.value].name,
      pageNum: 1,
      list: []
    })
    this.getList()
  },
  onChange2 (e) {
    this.setData({
      selectList2: e.detail.value,
      pageNum: 1,
      list: []
    })
    this.getList()
  },

  scrollBottom (e) {
    this.setData({
      pageNum: this.data.pageNum += 1
    })
    this.getList()
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow () {
    if (this.data.needFresh) {
      this.setData({
        pageNum: 1,
        list: []
      })
      this.getList()
    }
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage () {

  }
})